package Solution151_175;

import org.junit.Test;

import java.util.LinkedList;
import java.util.PriorityQueue;

public class Solution155最小栈 {
    class MinStack {

        private LinkedList<Integer> linkedList;
        private PriorityQueue<Integer> priorityQueue;

        /**
         * initialize your data structure here.
         */
        public MinStack() {
            linkedList = new LinkedList<>();
            priorityQueue = new PriorityQueue<>();
        }

        public void push(int x) {
            linkedList.addFirst(x);
            priorityQueue.add(x);

        }

        public void pop() {
            Integer first=linkedList.removeFirst();
            priorityQueue.remove(first);

        }

        public int top() {
            return linkedList.getFirst();

        }

        public int getMin() {
            return priorityQueue.peek();
        }
    }

    @Test
    public void test(){
        MinStack minStack=new MinStack();
        minStack.push(-10);
        minStack.push(14);
        minStack.getMin();
        minStack.getMin();
        minStack.push(-20);
        minStack.getMin();
        minStack.getMin();
        minStack.top();
        minStack.getMin();
        minStack.pop();
        minStack.push(10);
        minStack.push(7);
        minStack.getMin();
        minStack.push(7);
        minStack.pop();
        minStack.top();
        minStack.getMin();
        minStack.pop();
    }

}
